/*
 * HeartBeatThread.java
 * Copyright November 23, 2012 Erik Strelzoff
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.magelord.servlet;

import com.magelord.utils.Logger;

/**
 * Runs the regular heart beat responsible for advancing game states.
 */
public class HeartBeatThread extends Thread {
	
	/**
	 * Thread go-stop control.
	 */
	public boolean m_keepRunning = true;
	
	public HeartBeatThread() {
	}
	
	/**
	 * Runnable loop.
	 */
	public void run() {
		while (m_keepRunning) {
			try {
				// Sleep between handling heartbeats.
				try { 
					sleep(10000);
				} catch (InterruptedException e) {
				}
				
				// Walk through list of GameStates
				// Order GameStates by scheduled time of next heartbeat, ascending.
				// Process pending ones in order.  When we hit a gamestate scheduled
				// in the future, loop around.
				//
				// But for no, only consider the one test gamestate.
				//
				
				
				
			} catch (Exception e) {
				Logger.error("HeartBeatThread: Unhandled exception", e);
			} catch (Error e) {
				break;
			}
		}
	}
	
	public void softStop() {
		m_keepRunning = false;
	}
}
